
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sim_uart.h
  * @author     baiyang
  * @date       2022-12-3
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include <stdint.h>
#include <stdbool.h>

#include <rtthread.h>
#include <ipc/ringbuffer.h>

#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/
typedef struct sim_uart* sim_uart_t;
typedef const struct sim_uart* sim_uart_const_t;

struct sim_uart {
    struct rt_device _parent;

    int fd;
    struct sockaddr_in sockaddr_i;

    rt_thread_t thread_ctx;

    struct rt_ringbuffer rxbuf;
    uint8_t rxbuf_pool[2048];

    bool _is_udp;
    bool _connected;
    bool _use_socket_connected;
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
int  sim_uart_init(sim_uart_t uart, const char* dev_name, const char *path, uint16_t tcp_base_port, uint16_t udp_port_offset);
/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif



